//
//  UIView+WNFrame.m
//  iOSOCProjectDirectory
//
//  Created by BHmac on 2017/6/9.
//  Copyright © 2017年 XieXuan. All rights reserved.
//

#import "UIView+WNFrame.h"

CGFloat pointAdapt6(CGFloat point) {
    CGFloat standard = 375.0;
    int screenwidth = (int)[UIScreen mainScreen].bounds.size.width;
    
    switch (screenwidth) {
        case 320:
            return point*(320/standard);
        case 375:
            return point*(375/standard);
        case 414:
            return point*(414/standard);
        default:
            return point*(screenwidth/standard);
    }
    return point;
}

CGFloat pointAdaptHeight6(CGFloat point) {
    CGFloat standard = 667.0;
    int screenHeight = (int)[UIScreen mainScreen].bounds.size.height;
    
    switch (screenHeight) {
        case 480:
            return point*(480/standard);
        case 568:
            return point*(568/standard);
        case 667:
            return point*(667/standard);
        case 736:
            return point*(736/standard);
        default:
            return point*(screenHeight/standard);
    }
    return point;
}

CGFloat pointAdapt4(CGFloat point) {
    CGFloat standard = 320.0;
    int screenwidth = (int)[UIScreen mainScreen].bounds.size.width;
    
    switch (screenwidth) {
        case 320:
            return point*(320/standard);
        case 375:
            return point*(375/standard);
        case 414:
            return point*(414/standard);
        default:
            return point*(screenwidth/standard);
    }
    
    return point;
}


@implementation UIView (WNFrame)

+ (instancetype)dfzy_viewFromXib
{
    return [[NSBundle mainBundle]loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}


+ (instancetype)xmg_viewFromXib
{
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(self) owner:nil options:nil].firstObject;
}

- (BOOL)dfzy_intersectsWithView:(UIView *)view
{
    //以 self 的左上角为坐标原点,将 self.bounds 的坐标系转换为 self 所在的坐标系
    CGRect selfRect = [self convertRect:self.bounds toView:nil];
    CGRect viewRect = [view convertRect:view.bounds toView:nil];
    
    return CGRectIntersectsRect(selfRect, viewRect);
}


- (void)setX:(CGFloat)x
{
    CGRect frame = self.frame;
    frame.origin.x = x;
    self.frame = frame;
}

- (CGFloat)x
{
    return self.frame.origin.x;
}

- (void)setY:(CGFloat)y
{
    CGRect frame = self.frame;
    frame.origin.y = y;
    self.frame = frame;
}

- (CGFloat)y
{
    return self.frame.origin.y;
}

- (void)setWidth:(CGFloat)width
{
    CGRect frame = self.frame;
    frame.size.width = width;
    self.frame = frame;
}

- (CGFloat)width
{
    return self.frame.size.width;
}

- (void)setHeight:(CGFloat)height
{
    CGRect frame = self.frame;
    frame.size.height = height;
    self.frame = frame;
}

- (CGFloat)height
{
    return self.frame.size.height;
}

- (void)setOrigin:(CGPoint)origin
{
    CGRect frame = self.frame;
    frame.origin = origin;
    self.frame = frame;
}

- (CGPoint)origin
{
    return self.frame.origin;
}

-(void)setSize:(CGSize)size
{
    CGRect frame = self.frame;
    frame.size = size;
    self.frame = frame;
}

-(CGSize)size
{
    return self.frame.size;
}


@end
